<?php

namespace app\api\controller\user;

use app\api\controller\AuthController;
use app\api\service\UserCollectGroupGoodsService;

class CollectGroupGoodsController extends AuthController
{
    public function index()
    {
        $user_id = $this->request->user['user_id'];

        $goodsList = UserCollectGroupGoodsService::getUserCollectGroupGoodsList($user_id);

        return json(['code' => 1, 'data' => $goodsList, 'msg' => '请求成功!']);
    }

    public function save()
    {
        $group_goods_id = $this->request->param('group_goods_id/d');
        if (empty($goods_id)){
            return json(['code' => 0, 'msg' => '非法参数!']);
        }
        $user_id = $this->request->user['user_id'];

        $result = UserCollectGroupGoodsService::saveUserCollectGroupGoods($user_id,$group_goods_id);

        return $result ? json(['code' => 1, 'msg' => '收藏成功!']) : json(['code' => 0, 'msg' => '收藏失败!']);
    }

    /**
     * 删除收藏商品
     * */
    public function delete()
    {
        $param = $this->request->param('group_goods_ids');

        if (empty($param)){
            return json(['code' => 0, 'msg' => '非法参数!']);
        }


        $user_id = $this->request->user['user_id'];

        $result = UserCollectGroupGoodsService::deleteUserCollectGroupGoods($user_id,$param);

        return $result ? json(['code' => 1, 'msg' => '删除成功!']) : json(['code' => 0, 'msg' => '删除失败!']);
    }
}